package leetcode.社招.华为;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author ：zsy
 * @date ：Created 2022/10/24 8:40 PM
 * @description：
 */
public class Main {

    public static void main(String[] args) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
        PropertyDescriptor propertyDescriptor = new PropertyDescriptor("name", User.class);
        Method readMethod = propertyDescriptor.getReadMethod();
        Method writeMethod = propertyDescriptor.getWriteMethod();
        User user = new User();
        user.setName("zhangsan");
        System.out.println(readMethod.invoke(user));
        System.out.println(writeMethod.invoke(user, "wangwu"));
        System.out.println(readMethod.invoke(user));
        Field[] fields = User.class.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(propertyDescriptor.getValue(field.getName()));
        }
    }


    static class User {
        private String name;
        private String val;

        private String getPass() {
            return null;
        }

        public String getName() {
            return this.name;
        }

        public String getVal() {
            return this.val;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setVal(String val) {
            this.val = val;
        }
    }
}

